﻿using System;
using System.Collections.Generic;
using System.Text;

namespace T.FAS.Runtime.Base.Entity
{
    public class ExpressionPluginAttribute: Attribute
    {
        /// <summary>
        /// 定义表达式插件类中哪些属于字段，使用英文逗号隔开
        /// </summary>
        public string[] Fields { get; }

        /// <summary>
        /// 定义表达式插件类中哪些属于方法，使用英文逗号隔开
        /// </summary>
        public string[] Methods { get; }

        /// <summary>
        /// 插件配置信息，json格式
        /// </summary>
        public string Config { get; }

        public ExpressionPluginAttribute(string methods)
        {
            Methods = GetFieldsOrMethods(methods);
        }

        public ExpressionPluginAttribute(string methods, string fields)
        {
            Methods = GetFieldsOrMethods(methods);
            Fields = GetFieldsOrMethods(fields);
        }

        public ExpressionPluginAttribute(string methods, string fields, string config)
        {
            Methods = GetFieldsOrMethods(methods);
            Fields = GetFieldsOrMethods(fields);
            Config = config;
        }

        private string[] GetFieldsOrMethods(string fields)
        {
            if (string.IsNullOrEmpty(fields)) return null;
            else
            {
                return fields.Split(',');
            }
        }
    }
}
